package com.service.weChatWifiLogin.controller;



import com.service.config.utils.Result;
import com.service.weChatWifiLogin.dto.BossRegisterDto;
import com.service.weChatWifiLogin.paramVo.SsidAddVo;

import com.service.weChatWifiLogin.service.CustomerOrBossService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Random;

/**
 * wifi连接接口<br>
 *
 * @className: WifiController
 * @package: com.service.newwifilogin.controller
 * @author: mamingcong
 * @date: 2020/8/6 14:04
 */
@Api(tags = "WIFI连接接口")
@RestController
public class WifiController {

    @Resource
    private CustomerOrBossService  customerOrBossService;
    @ApiOperation(value = "查询微信用户")
    @GetMapping(value = "/queryWeiUser")
    public Result queryWeiUser1(@RequestParam(value = "code") @ApiParam("微信二维码code") String code,
                                @RequestHeader(value = "token",required = false) @ApiParam("token令牌") String bAuthToken,
                                @RequestParam(value = "flag") @ApiParam("标识符 1--boss 2--顾客") String flag,
                                @RequestParam(value = "nickName" ,required = false) @ApiParam("昵称") String nickName) {
        try {
            return customerOrBossService.queryCode1(bAuthToken,code, flag,nickName);
        } catch (Exception e) {
            return Result.failure(1001, e.getMessage());
        }
    }
    @ApiOperation(value = "boss注册")
    @PostMapping(value = "/addWeiUser")
    public Result addWeiUser(@RequestBody BossRegisterDto bossRegisterDto) {
        try {
            return customerOrBossService.addWeiUser(bossRegisterDto);
        } catch (Exception e) {
            return Result.failure(1001, e.getMessage());
        }
    }
    @ApiOperation(value = "解密手机号")
    @PostMapping(value = "/decrypt")
    public Result decrypt(@RequestParam(value = "code") @ApiParam("微信二维码code") String code ,
                          @RequestParam(value = "encryptedData") @ApiParam("包括敏感数据在内的完整用户信息的加密数据")String encryptedData,
                          @RequestParam(value = "iv")@ApiParam("加密算法的初始向量")String iv,
                          @RequestParam(value = "flag") @ApiParam("标识符 1--boss 2--顾客") String flag) {
        try {
            return customerOrBossService.decrypt(code,encryptedData,iv,flag);
        } catch (Exception e) {
            return Result.failure(1001, e.getMessage());
        }
    }

}
